<?php
class CanbosController extends AppController {

	var $name = 'Canbos';


	function index() {
		$this->Canbo->recursive = 0;
		$this->set('canbos', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid canbo', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('canbo', $this->Canbo->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Canbo->create();
			if ($this->Canbo->save($this->data)) {
				$this->Session->setFlash(__('The canbo has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The canbo could not be saved. Please, try again.', true));
			}
		}
		$hochams = $this->Canbo->Hocham->find('list',array('fields'=>'tenhocham'));
		$hocvis = $this->Canbo->Hocvi->find('list',array('fields'=>'tenhocvi'));
		$donvis = $this->Canbo->Donvi->find('list',array('fields'=>'tendonvi'));
		$this->set(compact('hochams', 'hocvis', 'donvis'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid canbo', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Canbo->save($this->data)) {
				$this->Session->setFlash(__('The canbo has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The canbo could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Canbo->read(null, $id);
		}
		$hochams = $this->Canbo->Hocham->find('list',array('fields'=>'tenhocham'));
		$hocvis = $this->Canbo->Hocvi->find('list',array('fields'=>'tenhocvi'));
		$donvis = $this->Canbo->Donvi->find('list',array('fields'=>'tendonvi'));
		$this->set(compact('hochams', 'hocvis', 'donvis'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for canbo', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Canbo->delete($id)) {
			$this->Session->setFlash(__('Canbo deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Canbo was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
    
    function find(){
        
   if(!empty($this->data)){
          {
            
                         $data=$this->data;
                       
                         $dulieu=$data['Canbo'];
                       //  $dieukientim=$data['tim'];
                   if(!empty($dulieu['noidung']))
                    { 
                         $thongtin=$this->Canbo->find('all',array('conditions'=>array($dulieu['tim'].' LIKE '=>'%'.$dulieu['noidung'].'%')));
          
                          
                  }
                
         } 
      $this->set(compact('thongtin'));
     }    
    }
    function auto() {
        
    
        $this->layout = 'ajax';
        $com=$this->Canbo->find('all', array('conditions' => array('Canbo.ten LIKE' => $this->params['url']['q'].'%')));
        $this->set(compact('com'));
    }    
}
